package oo;

import java.util.ArrayList;
import java.util.List;

import javax.faces.event.ValueChangeEvent;
import javax.faces.model.SelectItem;

import entity.ZsmOgloszenie;

import modalpanel.ModalPanel;

import package_.Klasa_;

import sesja.sesja_interface;
import sesja.sesjaimpl;
import szkola_database_entity.SzkolaUser;
import zsm.zsm_;

import baza_mysql.Database;

public class rejestracja {//extends login{

	private sesja_interface sesja;
	private String przycisk="1",name,haslo,email,selection,v1,v2;
	
	public String getV1() {
		return v1;
	}
	public void setV1(String v1) {
		this.v1 = v1;
	}
	public String getV2() {
		return v2;
	}
	public void setV2(String v2) {
		this.v2 = v2;
	}
	public String getSelection() {
		System.out.println("2");
		return selection;
	}
	public void setSelection(String selection) {
		System.out.println("1");
		this.selection = selection;
	}
	private Klasa_ kl;
	private SzkolaUser sz;
	private ModalPanel mp;
	private List <SelectItem> testList,dataList = new ArrayList<SelectItem>();
	private List <Animal> listValues = new ArrayList<Animal>();
	private List<String> configurations=new ArrayList<String>();
	
	public List<SelectItem> getDataList() {
		return dataList;
	}
	public void setDataList(List<SelectItem> dataList) {
		this.dataList = dataList;
	}
	public List<String> getConfigurations() {
		return configurations;
	}
	public void setConfigurations(List<String> configurations) {
		this.configurations = configurations;
	}
	public void processValueChange(){};
	public void selectionChanged(ValueChangeEvent evt) {
	        String selectedInfo="";
	    	Object newValue =  evt.getNewValue();
	    	System.out.println(">>"+newValue);
	    	Object[] selectedValues = null;
	    	if (newValue instanceof List) {
	    		List list = (List)newValue;
	    		selectedValues = list.toArray();
	    	} else if (newValue instanceof Object[] ) {
	        	selectedValues = (Object[]) evt.getNewValue();
	    	} 
	    	
	    	if (selectedValues.length == 0) {
	            selectedInfo = "No selected values";
	        } else {
	            StringBuffer sb = new StringBuffer("Selected values: ");
	            for (int i = 0; i < selectedValues.length; i++) {
	                if (i > 0) { 
	                    sb.append(", ");
	                }    
	                
	                sb.append(selectedValues[i]);
	            }
	            selectedInfo = sb.toString();
	        }
	    }
	public List<Animal> getListValues() {
		System.out.println("2getListValues");
		return listValues;
	}
	public void setListValues(List<Animal> listValues) {
		System.out.println("1setListValues");
		this.listValues = listValues;
	}
	public List<SelectItem> getTestList() {
		return testList;
	}
	public void setTestList(List<SelectItem> testList) {
		this.testList = testList;
	}
	public static final String[][] array=
		{{"n","menu_nauczyciel"},{"s","menu_student"},{"a","menu_admin"}};
	
	public ModalPanel getMp() {
		return mp;
	}
	public void setMp(ModalPanel mp) {
		this.mp = mp;
	}
	public String getPrzycisk() {
		return przycisk;
	}
	public void setPrzycisk(String przycisk) {
		this.przycisk = przycisk;
	}
	public rejestracja(){
		mp=new ModalPanel();
		/*testList.add(new SelectItem("polecat","1"));
    	testList.add(new SelectItem("suricate","2"));
    	testList.add(new SelectItem("marshotter","3"));
    	testList.add(new SelectItem("dog","4"));
    	testList.add(new SelectItem("cat","5"));
    	testList.add(new SelectItem("bear","6"));*/
    	dataList.add(new SelectItem("cat","a"));
    	dataList.add(new SelectItem("bear","a1"));
    	dataList.add(new SelectItem("wolf","a2"));
    	configurations.add("a");
    	configurations.add("b");
    	name="";haslo="";
	}
	private void blad(String ... a){
		System.out.println("(Klasa)>"+a[0]+"(Metoda)>"+a[1]+ "(blad)>"+a[2]);
	}
	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getHaslo() {
		return haslo;
	}
	public void setHaslo(String haslo) {
		this.haslo = haslo;
	}
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	private void czysc(){
		name=haslo=email="";
	}
	public String rejestruj(){
		return "rejestruj";
	}
	private void clear_fields(){
		this.setEmail("");
		this.setHaslo("");
		this.setName("");
	}
	private void przypisz(){
		sz.setEmail(getEmail());
		sz.setNazwa(getName());
		//sz.setPassword(this.getHaslo());
		sz.setRola("n");
	}
	public void addd() {//throws MateuszException{
		/*ZsmOgloszenie u =new ZsmOgloszenie();
		u.setNazwa("test");
		System.out.println(zsm_.dodajogloszenie(u));*/
		}
	//public String loguj(){
		public void loguj(){
		/*sz=new SzkolaUser();
		sz.setEmail(getEmail());
		sz.setNazwa(getName());
		przypisz();
		SzkolaUser log_ok;
		if((log_ok=Klasa_.finduser_(sz))!=null){
			//add user email to session
			//sesjaimpl ses=new sesjaimpl();
			//sesjaimpl.F_insert_value_into_session("us", sz.getEmail());
			//Klasa_.updateUserSession(log_ok,ses.F_getStr_sessionId());
			String rola=Klasa_.getRolaIfExist(log_ok);
			for(int a=0;a<array.length;a++)
				if(array[a][0].equals(rola))
					return array[a][1];
		}
		else
		{*/
			mp.setNaglowek("Logowanie");
			mp.setTresc("Brak u�ytkownika o podanych danych.");
			mp.setWynik(true);
		/*}*/
		//return "menu_nauczyciel";//"null;
	}
	public String wyloguj(){
		//pobranie danych sesji od usera i danych z sesji webowej,jesli ok, wylogowanie usera
		sz=new SzkolaUser();
		SzkolaUser log_ok;
		/*if (sesjaimpl.F_get_value_into_session("us")!=null)
		{
			sz.setEmail(sesjaimpl.F_get_value_into_session("us"));
			if((log_ok=Klasa_.finduser_(sz))!=null){
				Klasa_.updateUserSession(log_ok,"");
				sesjaimpl.F_delete_value_from_session("us");
			}
		}*/
		return "start";
	}
	public void dodaj(){
		if (name.equals("") )
			v1="brak";
		else
			v1="";
		if ( haslo.equals(""))
			v2="brak";
		else
			v2="";
	}
}
